using Forecast.Business;
using Forecast.Database;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;

namespace Forecast.Business.Test
{
    [TestFixture]
    public class TestActivatePrediction
    {
        #region Variables

        private ActivatePrediction _activatePredicition;
        private IList<Player> _players;
        private Prediction _prediction;

        #endregion
        #region Setup / Teardown

        [SetUp]
        public void Setup()
        {
            _players = Mocks.GetAllPlayers();
            _prediction = Mocks.GetPrediction();
            _prediction.EndDate = DateTime.MaxValue;
            _prediction.IsActive = false;
            _activatePredicition = new ActivatePrediction();
        }

        #endregion
        #region Tests

        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void NullPrediction()
        {
            _activatePredicition.Execute(null, _players);
        }

        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void NullPlayers()
        {
            _activatePredicition.Execute(_prediction, null);
        }

        [Test]
        public void NewsItemCreated()
        {
            _activatePredicition.Execute(_prediction, _players);
            Assert.IsNotNull(_activatePredicition.ActivatePredictionNewsItem);
        }

        [Test]
        public void HoldingsCreated()
        {
            _activatePredicition.Execute(_prediction, _players);
            Assert.AreEqual(4, _activatePredicition.ActivatePredictionHoldings.Count);
        }

        [Test]
        public void HoldingCorrectNumberOfPredictioms()
        {
            _activatePredicition.Execute(_prediction, _players);
            for (int i = 0; i < 4; i++)
                Assert.AreEqual(50, _activatePredicition.ActivatePredictionHoldings[i].NumPredictions);
        }

        [Test]
        public void HoldingCorrectPrediction()
        {
            _activatePredicition.Execute(_prediction, _players);
            for (int i = 0; i < 4; i++)
                Assert.AreEqual(MockIds.PREDICTION, _activatePredicition.ActivatePredictionHoldings[i].PredictionId);
        }

        [Test]
        public void HoldingPlayerAdded()
        {
            _activatePredicition.Execute(_prediction, _players);
            for (int i = 0; i < 4; i++)
                Assert.Greater(_activatePredicition.ActivatePredictionHoldings[i].PlayerId, 0);
        }

        [Test]
        public void PlayersGotMoney()
        {
            _activatePredicition.Execute(_prediction, _players);
            Assert.AreEqual(1000, _activatePredicition.ActivatePredictionPlayers[0].Cash);
            Assert.AreEqual(1000, _activatePredicition.ActivatePredictionPlayers[1].Cash);
            Assert.AreEqual(1000, _activatePredicition.ActivatePredictionPlayers[2].Cash);
            Assert.AreEqual(1500, _activatePredicition.ActivatePredictionPlayers[3].Cash);
        }

        [Test]
        public void PredictionActivated()
        {
            _activatePredicition.Execute(_prediction, _players);
            Assert.AreEqual(true, _activatePredicition.ActivatePredictionPrediction.IsActive);
        }

        #endregion
    }
}
